package com.lagou.kafka.Kafka;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.Optional;

/**
 * @author: yehw
 * @date: 2020/8/19 01:51
 * @description: 消费者
 */
@Component
public class ConsumerMessage {

    @KafkaListener(topics = "topic-nginx")
    public void onMessage(ConsumerRecord<Integer, String> record) {
        Optional<ConsumerRecord<Integer, String>> optional = Optional.ofNullable(record);
        if (optional.isPresent()) {
            System.out.println("消费者获得信息："+record.topic() + "\t" + record.partition() + "\t" + record.offset() + "\t" + record.key() + "\t" + record.value());

        }
    }
}
